package cn.codestack.vueboot.common;

/**
 * @author icanci
 * @date Created in 2021/09/11 23:09
 * @version 1.0
 */

public class R {
    private boolean ok;
    private int     code;
    private String  message;
    private Object  obj;

    public boolean isOk() {
        return ok;
    }

    public void setOk(boolean ok) {
        this.ok = ok;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }

    public static R success() {
        R r = new R();
        r.setOk(true);
        r.setCode(200);

        return r;
    }

    public static R success(int code) {
        R r = new R();
        r.setOk(true);
        r.setCode(code);
        return r;
    }

    public static R success(int code, String message) {
        R r = new R();
        r.setOk(true);
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

    public static R success(int code, String message, Object obj) {
        R r = new R();
        r.setOk(true);
        r.setCode(code);
        r.setMessage(message);
        r.setObj(obj);
        return r;
    }

    public static R success(Object obj) {
        R r = new R();
        r.setOk(true);
        r.setCode(200);
        r.setMessage("success");
        r.setObj(obj);
        return r;
    }

    public static R fail() {
        R r = new R();
        r.setOk(false);
        r.setCode(201);

        return r;
    }

    public static R fail(int code) {
        R r = new R();
        r.setOk(false);
        r.setCode(code);
        return r;
    }

    public static R fail(int code, String message) {
        R r = new R();
        r.setOk(false);
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

    public static R fail(int code, String message, Object obj) {
        R r = new R();
        r.setOk(false);
        r.setCode(code);
        r.setMessage(message);
        r.setObj(obj);
        return r;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("R{");
        sb.append("ok=").append(ok);
        sb.append(", code=").append(code);
        sb.append(", message='").append(message).append('\'');
        sb.append(", obj=").append(obj);
        sb.append('}');
        return sb.toString();
    }
}
